package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworks
 * Date: 8/21/13
 * Time: 9:02 AM
 * To change this template use File | Settings | File Templates.
 */
public class Library {

    public HashMap<String, Boolean> libraryCollection;
    private PrintStream printer;

    public Library(PrintStream printer, ArrayList<String> books){
      this.printer = printer;
      libraryCollection = new HashMap<String, Boolean>();
      for (String book : books)
          addBook(book);
  }

    public void addBook(String title) {
        libraryCollection.put(title, true);
    }

    public void displayBookList() {
        if (libraryCollection.isEmpty())
            printer.println("No available books.");
        else {
            for (String title : libraryCollection.keySet())
                printer.println(title);
        }

    }

    public void checkBookAvailability(String userInput) {
        if (libraryCollection.containsKey(userInput)){
            printer.println("Thank You! Enjoy the Book");
            libraryCollection.put(userInput, false);
        }
        else {
            printer.println("Sorry we don't have that book yet.");
        }
    }
}

